package com.ddf.springdata.jpa.entity;

import com.ddf.springdata.jpa.dao.UserRepository;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * @author DDf on 2018/9/24
 *
 * 两个互相引用的对象如果自己的toString都需要调用对方的toString则会陷入死循环
 * @ToString(exclude = {"idCard"})
 *
 * @NamedEntityGraph {@link UserRepository#getByUsername}
 */
@Entity
@Table(name = "USER")
@Data
@ToString(exclude = {"idCard"}, callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@NamedEntityGraph(name = "User.detail",
        attributeNodes = @NamedAttributeNode("idCard"))
public class User extends BaseDomain {
    @Column(name = "USER_NAME")
    private String username;
    @Column(name = "PASSWORD")
    private String password;
    @Column(name = "BIRTH_DAY")
    @Temporal(value = TemporalType.DATE)
    private Date birthDay;
    @Transient
    private String message;
    @OneToOne(mappedBy = "user")
    private IdCard idCard;
}
